#include <bits/stdc++.h>
using namespace std;
map<string,vector<string>> mp;
int main()
{
  string s,author,bookname;
  ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
  int n; cin >>n;
  int i;
  for(i=0;i<n;++i)
  {
    cin >>s;
    if(s=="find") 
    {
      cin >>author;
       cout <<mp[author].size()<<'\n';
    }
    else if(s=="add")
    {
      cin >>bookname>>author;
      mp[author].push_back(bookname);
    }
  }
  return 0;
}
